import React from 'react';
import loadjs from 'loadjs';
import { Tools } from 'weaver-mobile';


export default class CloseWindow extends React.Component {
    constructor(props) {
        super(props);
        this.state = {
            src: "",
        };
        if(!window.em) {
            this.loadEmJs();
        }

    }
    componentWillMount() {
        this.closewindow();
    }

    loadEmJs = () => {
        try {
            let options = {
                method: 'GET',
                url: '/api/ec/dev/app/test',
            };
            Tools.callApi(options).then(res => {
                const {em_url_open} = res;
                if (em_url_open) {
                    if (loadjs) {
                        loadjs(em_url_open + "/open/js/jem.js")
                    }
                }
            });
        }catch(e) {

        }
    }

    closewindow = () => {
        if (this.isMobile() && window.em && window.em.checkJsApi("postBroadcast")) {
            window.em.postBroadcast({
                name: "qysSubmitWorkflowForm",
                text: 0
            });
            window.em.closeWindow();
        }
    }

    isMobile = () => {
        const ua = window.navigator.userAgent;
        let ismobile = /.*E-Mobile7.*/.test(ua) || /.*E-Mobile\/7.*/.test(ua);
        return ismobile;
    }




    render() {
        return <div style={{height: "100%", width: "100%", "background-color": "#f4f4f4"}}>
        </div>
    }

}
